package com.tgy.MyFlowable.workflow.util;


import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * 会签一票否决工具类
 */
@Component(value = "bpmCounterSignUtil")
public class BpmCounterSignUtil implements Serializable{

	private static final long serialVersionUID = 1L;

	/**
	 * 获取会签是否结束
	 * @param execution 当前执行实例
	 * @return 是否结束
	 */
	public boolean getComplete(DelegateExecution execution) {
		//会签环节中已完成的实例数量
	    int nrOfCompletedInstances = (int) execution.getVariable("nrOfCompletedInstances");
	    //会签环节中未完成的实例数量
	    int nrOfInstances = (int) execution.getVariable("nrOfInstances");
	    //否决判断，一票否决
	    if(execution.getVariable("rejected") != null) {
	    	int rejectCount = (int) execution.getVariable("rejected");
	    	if(rejectCount >0) {
	    		//输出方向为拒绝
	    		execution.setVariable("outcome", "reject");
	    		//一票否决，其余实例没必要做，结束
	    		return true;
	    	}
	    }

	    //所有实例任务未全部做完则继续其他实例任务
	    if(nrOfCompletedInstances != nrOfInstances) {
	    	return false;
	    }else {
	    	//会签结果全为赞同，输出方向未赞同
	    	execution.setVariable("outcome", "agree");
	    	return true;
	    }


	}

}
